<?php
defined('BASEPATH') or exit('No direct script access allowed');
session_start();

class Resources extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model("resource_model");
        $this->load->helper("url");
        $this->load->helper("uuid");
        $this->load->helper("date");
    }

    public function index()
    {
        if (!isset($_SESSION["user"])) {
            redirect("login");
            return;
        }
        $resources = $this->resource_model->getAll();
        $data["title"] = "资源管理";
        $data["resources"] = $resources;
        $this->load->view("templates/header", $data);
        $this->load->view("resources/resources", $data);
        $this->load->view("templates/footer");
    }

    public function create()
    {
        if (!isset($_SESSION["user"])) {
            redirect("login");
            return;
        }

        $data = array(
            "id" => create_uuid(),
            "collect_time" => date("Y-m-d H:i:s", now()),
            "status" => 0
        );
        $sub_name = $this->input->post("sub_name");
        $token = $this->input->post("token");
        $cookie = $this->input->post("cookie");
        $note = $this->input->post("note");

        $data["sub_name"] = $sub_name ? $sub_name : "";
        $data["token"] = $token ? $token : "";
        $data["cookie"] = $cookie ? $cookie : "";
        $data["note"] = $note ? $note : "";

        $this->resource_model->create($data);

        redirect("resources");
    }
}

?>